/**
 * 椭圆
 */
class CurveFlag extends AreaPlotBase {

  constructor(points) {
    super(points);
  }


  get_minPointCount() {
    return 2;
  }

  create() {
    let n = this.points.Count;
    if (n >= 2 && this.points[n - 1] != this.points[n - 2]) {
      let startPnt = this.points[0];
      let endPnt = this.points[1];
      let flagPnt1 = {X: startPnt.X, Y: endPnt.Y};
      let flagPnt2 = super.getMidPoint(startPnt, flagPnt1);
      let flagPnt3 = {X: endPnt.X, Y: flagPnt2.Y};
      let flagPnt4 = {X: endPnt.X, Y: startPnt.Y};
      let shift = super.distance(startPnt, flagPnt2) / 2;
      let len = super.distance(startPnt, flagPnt4);
      let temPnt = super.getThirdPoint(flagPnt4, startPnt, 0, len / 4, LEFT_SIDE);
      let curvePnt1 = super.getThirdPoint(startPnt, temPnt, Math.PI * 1.5, shift, RIGHT_SIDE);
      temPnt = super.getThirdPoint(flagPnt4, startPnt, 0, len / 4 * 3, LEFT_SIDE);
      let curvePnt2 = super.getThirdPoint(startPnt, temPnt, Math.PI * 1.5, shift, LEFT_SIDE);
      temPnt = super.getThirdPoint(flagPnt3, flagPnt2, 0, len / 4, LEFT_SIDE);
      let curvePnt3 = super.getThirdPoint(flagPnt2, temPnt, Math.PI * 1.5, shift, RIGHT_SIDE);
      temPnt = super.getThirdPoint(flagPnt3, flagPnt2, 0, len / 4 * 3, LEFT_SIDE);
      let curvePnt4 = super.getThirdPoint(flagPnt2, temPnt, Math.PI * 1.5, shift, LEFT_SIDE);
      let controlPnts1 = [];
      controlPnts1.push(startPnt);
      controlPnts1.push(curvePnt1);
      controlPnts1.push(curvePnt2);
      controlPnts1.push(flagPnt4);
      let curve1 = super.getBezierPoints(controlPnts1);
      let controlPnts2 = [];
      controlPnts2.push(flagPnt2);
      controlPnts2.push(curvePnt3);
      controlPnts2.push(curvePnt4);
      controlPnts2.push(flagPnt3);
      let curve2 = super.getBezierPoints(controlPnts2);
      let pnts = [].concat(flagPnt1);
      pnts = pnts.concat(curve1);
      curve2.reverse();
      pnts = pnts.concat(curve2);
      let pc3 = [];
      for (let j = 0; j < pnts.length; j++) {
        pc3.push(pnts[j]);
      }
      if (pnts.Count > 0) {
        pc3.push(pnts[0]);
      }
      if (this.PartCount > 0) {
        this.RemovePart(0);
      }
      this.AddPart(pc3);
    }
  }
}
